import MsgManager from "./MsgManager";

export default class MsgSend{
    public static send(msgType:any,msg:any){
        
        // let msg:moveType.IC2S_SyncPosition = {
        //     x: 1,
        //     y: 2,
        //     str: `当我们搞定整个。`
        // }
        // let msg = move.C2S_SyncPosition.create(pos)
        let msgId = MsgManager.instance.getMsgId(msgType)
        if(!msgId){
            console.error("未知消息id");
            return
        }
        let msgInfo = {
            msgId: msgId,
            data: msgType.encode(msg).finish()
        }
        // let blobBody = new Blob([msgInfo.data])
        let allLength = 4 + 4 + msgInfo.data.length;
        // let buffer = new ArrayBuffer(allLength);
        let buffer = new Int8Array(8);

        let view = new DataView(buffer.buffer)
        view.setInt32(0, allLength);
        view.setInt32(4, msgInfo.msgId);
        let result = new Blob([view.buffer, msgInfo.data.buffer])
        
    }
}